package com.example.xm.service.impl;

import com.example.xm.entity.Typeentity;
import com.example.xm.entity.Userentity;
import com.example.xm.entity.dto.TypeDto;
import com.example.xm.exception.SerceiceException;
import com.example.xm.mapper.TypeMapper;
import com.example.xm.service.TypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {
@Autowired(required = false)
    TypeMapper typeMapper;
    @Override
    public void reg(Typeentity typeentity) {
        Typeentity entity=  typeMapper.selectByName(typeentity.getName());
        if(entity!=null){
            throw new SerceiceException(400,"分类名称存在");
        }
        typeMapper.insert(typeentity);
    }

    @Override
    public void update(Typeentity typeentity) {
        typeMapper.updateByPrimaryKeySelective(typeentity);
    }

    @Override
    public PageInfo<Typeentity> list(TypeDto dto) {
        PageHelper.startPage(dto.getPage(),dto.getSize());
        List<Typeentity> list= typeMapper.selectList(dto);
        PageInfo<Typeentity> userentityPageInfo = new PageInfo<Typeentity>(list);
        return userentityPageInfo;
    }

    @Override
    public void delete(int[] intArray) {
        typeMapper.delete(intArray);
    }
}




